<template>
    <div id="dayWork">
      <el-row>
        <el-col :span="6"><div class="grid-content"></div></el-col>
        <el-col :span="10">
          <div class="grid-content">
            <el-form :label-position="labelPosition" :rules="rules" ref="form" :model="form" label-width="80px">
              <el-form-item label="选择日期" prop="date">
                <el-col :span="24">
                  <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="form.date" style="width: 100%;"></el-date-picker>
                </el-col>
              </el-form-item>
              <el-form-item label="项目组"prop="group">
                <el-col :span="24">
                  <el-select style="width: 100%;" v-model="form.group" clearable placeholder="请选择项目组">
                    <el-option
                      v-for="item in groupOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item label="完成任务" prop="yestodaySuccess">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.yestodaySuccess"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item label="未完成" prop="yestodayFail">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.yestodayFail"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item label="输出成果" prop="result">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.result"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item label="今日计划" prop="todayPlan">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.todayPlan"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item label="需要支持" prop="help">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.help"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmit('form')">提交</el-button>
                <el-button @click="resetForm('form')">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
          </el-col>
        <el-col :span="8"><div class="grid-content"></div></el-col>
      </el-row>
    	
    </div>
</template>
<script>
export default {
  name: 'dayWork',
  data () {
    return {
      rules: {
        date: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
        group: [
          { required: true, message: '请选择项目组', trigger: 'change' }
        ],
        yestodaySuccess: [
          { required: true, message: '请输入已完成任务', trigger: 'blur' }
        ],
        yestodayFail: [
          { required: true, message: '请输入未完成任务', trigger: 'blur' }
        ],
        result: [
          { required: true, message: '请输入输出成果', trigger: 'blur' }
        ],
        todayPlan: [
          { required: true, message: '请输入今日计划', trigger: 'blur' }
        ],
        help: [
          { required: true, message: '请输入需要支持', trigger: 'blur' }
        ]
      },
      form: {
          date: '',
          group:'',
          yestodaySuccess: '',
          yestodayFail: '',
          result: '',
          todayPlan: '',
          help: ''
        },
        labelPosition: 'right',
        groupOptions:[]
    }
  },
  created() {
    this.getGroupList();
  },
  beforeDestroy() {},
  computed: {},
  mounted() {},
  methods: {
    onSubmit(formName) {
      console.log('submit!');
      this.$refs[formName].validate((valid) => {
          if (valid) {
            var self = this;
            self.postRequest("/daily/addDaily", {
              group_id:self.form.group,
              daily_date:self.form.date,
              completed_task:self.form.yestodaySuccess,
              uncompleted_task:self.form.yestodayFail,
              output_result:self.form.result,
              today_plan:self.form.todayPlan,
              need_help_content :self.form.help
            }).then(
              res => {      
                console.log(res)     
                if(res.data.result == '1' ){            
                  this.$message({
                      message: res.data.message,
                      type: 'success'
                  });
                  console.log(res)
                  self.$router.push('/index');
                }else if(res.data.result == '2' ){
                  this.$message({
                      message: res.data.message,
                      type: 'error'
                  });
                }
              }
            ); 
          }
      })
      
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getGroupList() {
      var self = this;
      //console.log(self.currentPage)
      self.getRequest("/base/common/queryProjectName?flug="+1, {}).then(
        res => {      
          console.log(res.resultData)     
          var obj = res.data.resultData;
            var arr = [];
            for(var i in obj) {
              var row = {};
              row.label = obj[i].pName;
              row.value = obj[i].id;
              arr.push(row);
            }
            //console.log(arr)
            self.groupOptions = arr;
        }
      );
    }
  }
}
</script>

<style scoped> 
  .grid-content {
    min-height: 36px;
  }
</style>